﻿using System.Collections.Generic;
using EscapeZone.Screens;
using EscapeZone.Serialization;

namespace EscapeZone.Mapping.Building
{
    public class MapElementBuilder
    {
        private Dictionary<ElementType, IMapElementBuilder> m_builders;

        public MapElementBuilder(EscapeGame game, GameScreen screen)
        {
            m_builders = new Dictionary<ElementType, IMapElementBuilder>();
            m_builders.Add(ElementType.Camera, new CameraBuilder(game, screen));
            m_builders.Add(ElementType.Guard, new GuardBuilder(game, screen));
        }

        public List<IMapElement> BuildElements(IEnumerable<IDefinition> definitions)
        {
            List<IMapElement> elements = new List<IMapElement>();

            foreach (var definition in definitions)
            {
                if (m_builders.ContainsKey(definition.Type))
                {
                    var element =  m_builders[definition.Type].Build(definition);
                    if (element != null)
                    {
                        elements.Add(element);
                    }
                }
            }

            return elements;
        }
    }
}